css: Make _gtk_css_selector_matches() take a path length
authorBenjamin Otte <otte@redhat.com>
Mon, 16 May 2011 18:20:55 +0000 (20:20 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 20:17:57 +0000 (22:17 +0200)
This will be necessary when handling inherit.

gtk/gtkcssprovider.c
gtk/gtkcssselector.c
gtk/gtkcssselectorprivate.h

index 2cf49ad1f11d906015cf094bcee4054016837637..fd2696a32ebb410160216ff1a422192028912b53 100644 (file)
@@ -1123,7 +1123,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
 
       info = g_ptr_array_index (priv->selectors_info, i);
 
-      if (!_gtk_css_selector_matches (info->selector, path))
+      if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path)))
         continue;
 
       g_hash_table_iter_init (&iter, info->style);
@@ -1175,7 +1175,7 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
 
       info = g_ptr_array_index (priv->selectors_info, i);
 
-      if (!_gtk_css_selector_matches (info->selector, path))
+      if (!_gtk_css_selector_matches (info->selector, path, gtk_widget_path_length (path)))
         continue;
 
       selector_state = _gtk_css_selector_get_state_flags (info->selector);
index 3850a9eaf472b46582dfe1ca4f5280369ba9a24f..35db9ca7ae5fc0046db3fd8f47aca6999a28eec3 100644 (file)
@@ -353,18 +353,32 @@ gtk_css_selector_matches_previous (const GtkCssSelector      *selector,
   return FALSE;
 }
 
+/**
+ * _gtk_css_selector_matches:
+ * @selector: the selector
+ * @path: the path to check
+ * @length: How many elements of the path are to be used
+ *
+ * Checks if the @selector matches the given @path. If @length is
+ * smaller than the number of elements in @path, it is assumed that
+ * only the first @length element of @path are valid and the rest
+ * does not exist. This is useful for doing parent matches for the
+ * 'inherit' keyword.
+ *
+ * Returns: %TRUE if the selector matches @path
+ **/
 gboolean
 _gtk_css_selector_matches (const GtkCssSelector      *selector,
-                           /* const */ GtkWidgetPath *path)
+                           /* const */ GtkWidgetPath *path,
+                           guint                      length)
 {
   GSList *list;
-  guint length;
   gboolean match;
 
   g_return_val_if_fail (selector != NULL, FALSE);
   g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (length <= gtk_widget_path_length (path), FALSE);
 
-  length = gtk_widget_path_length (path);
   if (length == 0)
     return FALSE;
 
index 70c5e600cfd689625b2e8fc2d6713427e760b07c..5a158824d81eacff2c44c429ba73a9fc537e9888 100644 (file)
@@ -48,7 +48,8 @@ void              _gtk_css_selector_print           (const GtkCssSelector   *sel
 GtkStateFlags     _gtk_css_selector_get_state_flags (GtkCssSelector         *selector);
 
 gboolean          _gtk_css_selector_matches         (const GtkCssSelector   *selector,
-                                                     /* const */ GtkWidgetPath *path);
+                                                     /* const */ GtkWidgetPath *path,
+                                                     guint                   length);
 int               _gtk_css_selector_compare         (const GtkCssSelector   *a,
                                                      const GtkCssSelector   *b);